package com.winchain.chainbill.bill.biz.transfer.rx;

import com.shell.framework.rx.OnErrorNotImplementedSubscriber;
import com.winchain.chainbill.bill.base.po.CbRec;
import com.winchain.chainbill.bill.base.po.CbXfe;
import com.winchain.chainbill.bill.base.service.CbXfeService;
import com.winchain.chainbill.bill.biz.Bill;
import com.winchain.chainbill.bill.biz.BillEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class BillXfeSubscriber extends OnErrorNotImplementedSubscriber<BillEvent<CbXfe>> {
	@Autowired
	private CbXfeService cbXfeService;

	public void onApplicationEvent(BillEvent<CbXfe> t) {
		CbRec record = t.getBill().getRec();
		CbXfe cbXfe = (CbXfe) t.getBill().getSource();
		if ((cbXfe != null) && (cbXfe.getXfeId() != null)) {
			cbXfe.setOptSeq(record.getOptSeq());
			this.cbXfeService.saveOrUpdate(cbXfe);
		}
	}
}
